package com.jiaai.web.zfp_back.gift;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.gift.api.IClubApi;
import com.jiaai.gift.model.ClubVO;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.*;

/**
 * class_name:ZBClubController
 * describe:------------------>至尊俱乐部
 * create_user:张昉平
 * create_date:2018/1/18
 * create_time:16:27
 */
@RestController
@RequestMapping("/api/v1/admin/club")
public class ZBClubController {

    @Reference
    private IClubApi iClubApi;

    @GetMapping("/list")
    public Object list(@RequestParam(required = false, defaultValue = "1") Integer curr){
        return RestResultGenerator.genSuccessResult(iClubApi.getAll(curr));
    }

    @GetMapping("/oneMems/{id}")
    public Object oneMems(@PathVariable Integer id){
        return RestResultGenerator.genSuccessResult(iClubApi.getOneMems(id));
    }

    @GetMapping("/last")
    public Object last(){
        return RestResultGenerator.genSuccessResult(iClubApi.last());
    }

    @PostMapping("/saveOrEdit")
    public Object saveOrEdit(@RequestBody ClubVO vo){
        try {
            iClubApi.saveOrUpdate(vo);
            return RestResultGenerator.genSuccessResult("操作成功");
        }catch (Exception e){
            if (e.getMessage().equals("BEFORE")){
                return RestResultGenerator.genErrorResult(600, "时间设置错误");
            }
            e.printStackTrace();
            throw e;
        }
    }

    @PostMapping("/delete/{id}")
    public Object delete(@PathVariable Integer id){
        iClubApi.delete(id);
        return RestResultGenerator.genSuccessResult("操作成功");
    }

}
